package org.lakesidecdc.outreach.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ImageBundle;
import com.google.gwt.user.client.ui.VerticalPanel;

public class TopPanel extends Composite implements ClickHandler {
	private Button addProjectButton = new Button("+");
	
	public interface Images extends ImageBundle {
		AbstractImagePrototype logo();
	}
	
	private Anchor signOutLink = new Anchor("Sign Out");
	
	public TopPanel() {
		HorizontalPanel outer = new HorizontalPanel();
		VerticalPanel inner = new VerticalPanel();
		
		outer.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
		inner.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
		
		HorizontalPanel links = new HorizontalPanel();
		links.setSpacing(4);
		links.add(signOutLink);
		
		//final Image logo = images.logo().createImage();
		final HTML logo = new HTML("<h2>Lakeside Outreach Manager</h2>");
		outer.add(logo);
		outer.setCellHorizontalAlignment(logo, HorizontalPanel.ALIGN_LEFT);
		
		outer.add(inner);
		outer.add(addProjectButton);
		inner.add(links);
		
		signOutLink.addClickHandler(this);
		addProjectButton.addClickHandler(this);
		
		initWidget(outer);
		setStyleName("project-TopPanel");
		links.setStyleName("project-TopPanelLinks");
	}
	
	public void onClick(ClickEvent event) {
		Object sender = event.getSource();
		if (sender == signOutLink) {
			Window.alert("Signed Out");
		} else if (sender == addProjectButton) {
			LakesideOutreachManager.get().getAddProjectPanel().show();
			LakesideOutreachManager.get().getAddProjectPanel().center();
		}
	}
	
	public void setSignOutLink(String signOutUrl) {
		signOutLink.setHref(signOutUrl);
	}
}
